package cb.tools;

import static org.jhotdraw.draw.AttributeKeys.DECORATOR_INSETS;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.geom.Point2D;
import java.net.URL;

import javax.swing.ImageIcon;
import org.jhotdraw.draw.RectangleFigure;
import org.jhotdraw.draw.TextFigure;
import org.jhotdraw.geom.Insets2DDouble;
import cb.images.Stream;

public class VoltageSource extends RectangleFigure
	{

		public VoltageSource()
			{
				super(10, 20, 10, 9);

//				TextFigure tf = new TextFigure();
//				setDecorator(tf);
//				// setDrawDecoratorFirst(true);
//				DECORATOR_INSETS.set(this, new Insets2DDouble(30, 10, 6, 10));

			}

		@Override
		protected void drawFill(Graphics2D g)
			{
				Image img;
				URL myurl = Stream.class.getResource("VS.gif");
				Toolkit tk = Toolkit.getDefaultToolkit();
				img = tk.getImage(myurl);
				g.drawImage(img, (int) rectangle.x, (int) rectangle.y, 60, 30,
						null);

			}


		@Override
		public void basicSetBounds(Point2D.Double anchor, Point.Double lead)
			{
				rectangle.x = Math.min(anchor.x, lead.x);
				rectangle.y = Math.min(anchor.y, lead.y);
				// edited rectangle to be a specific shape
				rectangle.width = 60;
				rectangle.height = 30;

			}

		/** Returns an ImageIcon, or null if the path was invalid. */
		protected ImageIcon createImageIcon(String path, String description)
			{
				java.net.URL imgURL = Stream.class.getResource(path);
				if (imgURL != null)
					{
						return new ImageIcon(imgURL, description);
					} else
					{

						System.err.println("Couldn't find file: " + path);
						return null;
					}
			}

	}
